// pages/shop-homepage/homepage.js
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    clickcat: false,
    class1index: 0,
    class2index: 0,
    ID: "",
    shopmsg: "",
    classall: "",
    nr: "",
    showxiala: false,
    carlist: "",
    showsxselect: false,
    selectall: false,
    obj: "",
    showcoupon: false,
    allmoney: 0,
    yixuan: 0,


    dayang: false,
    xiaxian: false,
    canclick: true,
    allcart: "",
    quedingcanclick: true,

    canadddandugoods: true,
    canminusdandugoods: true
  },
  //商家介绍
  shangjieshao: function(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/merchant-introduction/introduction?ID=' + id,
    })
  },
  // 搜索跳转
  sousuo: function() {
    wx.navigateTo({
      url: '/pages/merchant-search/search?shopid=' + this.data.shopmsg.ID,
    })
  },


  quzhezhao: function() {
    this.setData({
      dayang: false
    })
  },

  // 展开
  showxialafun: function() {

    console.log("1111111")
    this.setData({
      showxiala: !this.data.showxiala
    })

  },


  tosupermarketdetails: function(e) {
    var shopID = e.currentTarget.dataset.shopid
    var ID = e.currentTarget.dataset.id

    wx.navigateTo({
      url: '/pages/supermarket-details/details?shopID=' + shopID + "&ID=" + ID,
    })
  },

  showcoupon: function() {
    this.setData({
      showcoupon: !this.data.showcoupon
    })
  },
  // 左边检索

  leftlist: function(e) {
    var select = e.currentTarget.dataset.index;
    this.setData({
      class1index: select
    })
    if (this.data.classall[select].CategoryList[0] == null) {
      this.setData({
        class2index: -1
      })
    } else {
      this.setData({
        class2index: 0
      })
    }

    this.getnr()
  },

  // 右边检索
  rightlist: function(e) {
    var select = e.currentTarget.dataset.index;
    console.log(e.currentTarget)
    this.setData({
      class2index: select
    })

    this.getnr()
  },
  rightlist1: function(e) {
    var select = e.currentTarget.dataset.index;
    console.log(e.currentTarget)
    this.setData({
      class2index: select
    })
    this.showxialafun()
    this.getnr()
  },
  // 商品详情
  commodityDetails: function() {
    wx.navigateTo({
      url: '/pages/group-purchase-commodity/commodity',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000',
    })

    var ID = options.ID
    this.setData({
      ID: ID
    })

    this.getshopinfo()
    this.getclass()

    this.getshophuodong()
    this.getcart()

  },


  lijilingqu: function(e) {
    var UserCouponID = e.currentTarget.dataset.id
    ajax('/api/UploadReceiveCouponPrimaryNew/UploadAdd?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      UserCouponID: UserCouponID,
      ProvinceName: wx.getStorageSync('address_component').province,
      CityName: wx.getStorageSync('address_component').city,
      DistrictName: wx.getStorageSync('address_component').district,

    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      // console.log(res)

      wx.showToast({
        title: '领取成功',
        icon: 'none',
        duration: 2000
      })

      this.getshopinfo()
    })
  },

  lijifenxiang: function(e) {
    var UserCouponID = e.currentTarget.dataset.id

    ajax('/api/UploadReceiveCouponPrimary/UploadAdd?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      UserCouponID: UserCouponID,
      ProvinceName: wx.getStorageSync('address_component').province,
      CityName: wx.getStorageSync('address_component').city,
      DistrictName: wx.getStorageSync('address_component').district,

    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      if (res.Message == "上传成功!") {
        var id = UserCouponID;

        var rid = res.Status

        console.log(rid)
        wx.navigateTo({
          url: '/pages/unpacking-securities/securities?id=' + id + '&rid=' + rid,
        })
      }
    })


  },

  clickcatfun: function() {
    this.setData({
      clickcat: !this.data.clickcat
    })

    if (this.data.clickcat == true) {
      this.getcart()
    }
  },

  showsxselect: function() {
    var showsxselect = this.data.showsxselect
    this.setData({
      showsxselect: !showsxselect
    })
    if (showsxselect == true) {
      this.setData({
        canadddandugoods: true,
        canminusdandugoods: true,
        quedingcanclick: true
      })
    }
  },

  getshopinfo: function() {
    ajax('/api/ShopProduct/GetShopDetail?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        shopmsg: res.Models[0]
      })

      if (res.Models[0].IsOpen == 0) {
        this.setData({
          dayang: true
        })
      }
      if (res.Models[0].UseFlag == 0) {
        this.setData({
          xiaxian: true
        })
      }
    })
  },

  getclass: function() {
    ajax('/api/ShopProduct/GetShopAllCategory?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        classall: res.Models
      })

      this.getnr()

    })
  },

  getshophuodong: function() {
    ajax('/api/PosterPictures/Get?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      // ShopID: this.data.ID,
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        dnhd: res.Models
      })
    })
  },

  getnr: function() {
    // /api/ShopProduct/GetCateProduct?requestContent={
    // console.log(this.data.classall[this.data.class1index].ID)
    var that = this
    var ParentID
    // if(that.data.class2index==-1){
    //   ParentID = that.data.classall[that.data.class1index].ID
    // }else{
    //   ParentID = that.data.classall[that.data.class1index].CategoryList[that.data.class2index].ID
    // }
    ParentID = that.data.classall[that.data.class1index].ID

    console.log(ParentID)
    ajax('/api/ShopProduct/GetCateProduct?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: that.data.ID,
      ParentID: ParentID
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)
      this.setData({
        canadddandugoods: true,
        canminusdandugoods: true
      })

      if (that.data.class2index != -1) {
        if (res.Models != null) {
          that.setData({
            nr: res.Models[that.data.class2index]
          })
        } else {
          that.setData({
            nr: null
          })
        }
      } else {
        // console.log("111")
        if (res.Models != null) {
          that.setData({
            nr: res.Models[0]
          })
        } else {
          that.setData({
            nr: null
          })
        }
        // console.log(that.data.nr)
      }



    })
  },
  //清空购物车
  clearcart() {
    ajax('/api/ShopCart/DelCart?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,
      Type: 1,
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      this.getcart()
      this.getnr()
    })
  },

  copyobj: function(a) {

    var c = {};

    c = JSON.parse(JSON.stringify(a));

    return c;

  },

  //添加购物车
  clickadd: function(index) {
    var info = this.data.nr.ProList[index]
    console.log(info.IsSku)
    // console.log("11111111111")
    if (info.IsSku) {
      if (info.SkuName.length == 2) {
        // 有附加属性选择
        var obj = {}
        obj.stylelength = 2
        obj.index = index
        var SkuName = info.SkuName
        var SKUImgList = info.SKUImgList
        var canuselist = []
        for (var x in SKUImgList) {
          canuselist.push(SKUImgList[x].ANVS)
        }
        // obj.push(SkuName[0].AVName)
        for (var x in SkuName) {
          if (x == 0) {
            obj.yiji = SkuName[x].AVName
            obj.yijiANName = SkuName[x].ANName
            obj.selfnum = 1
          } else if (x == 1) {
            for (var y in obj.yiji) {
              var newlist = this.copyobj(SkuName[x].AVName)
              for (var m in newlist) {
                newlist[m].zi = obj.yiji[y].AVID + '_' + newlist[m].AVID
                // console.log(newlist[m].zi)
                if (canuselist.indexOf(newlist[m].zi) != -1) {
                  newlist[m].canuse = true
                  newlist[m].other = SKUImgList[canuselist.indexOf(newlist[m].zi)]
                  newlist[m].isselect = false
                } else {
                  newlist[m].canuse = false
                  newlist[m].isselect = false
                }
              }
              obj.yiji[y].xiaji = newlist
              obj.yiji[y].xiajiname = SkuName[x].ANName
              obj.yiji[y].isselect = false
            }
          }
          obj.yiji[0].isselect = true
          for (var x in obj.yiji[0].xiaji) {
            if (obj.yiji[0].xiaji[x].canuse) {
              obj.yiji[0].xiaji[x].isselect = true

              obj.morenselect = obj.yiji[0].xiaji[x].other
              break
            }
          }
        }
        console.log(canuselist)
        console.log(obj)
        this.setData({
          obj: obj
        })
      } else if (info.SkuName.length == 1) {
        var obj = {}
        obj.stylelength = 1
        obj.selfnum = 1
        obj.index = index

        var SkuName = info.SkuName
        var SKUImgList = info.SKUImgList
        var canuselist = []
        for (var x in SKUImgList) {
          canuselist.push(SKUImgList[x].ANVS)
        }
        console.log(canuselist)
        for (var x in SkuName) {
          var newlist = this.copyobj(SkuName[x].AVName)
          for (var y in newlist) {
            newlist[y].zi = newlist[y].AVID + "_" + "0"
            if (canuselist.indexOf(newlist[y].zi) != -1) {
              newlist[y].canuse = true
            } else {
              newlist[y].canuse = false
            }
            newlist[y].isselect = false
            newlist[y].other = SKUImgList[canuselist.indexOf(newlist[y].zi)]
          }
          for (var y in newlist) {
            if (newlist[y].canuse == true) {
              newlist[y].isselect = true

              obj.morenselect = newlist[y].other
              break
            }
          }

          // obj.yiji[0].isselect = true
          obj.yijiANName = SkuName[x].ANName
          obj.yiji = newlist

        }

        console.log(canuselist)
        console.log(obj)

        this.setData({
          obj: obj
        })

      }
      this.showsxselect()
    } else {
      // 无附加属性 
      this.addcart(index)
    }

  },

  selectyiji: function(e) {
    var index = e.currentTarget.dataset.index
    var str = "obj.yiji[" + index + "].isselect"
    for (var x in this.data.obj.yiji) {
      var str1 = "obj.yiji[" + x + "].isselect"
      this.setData({
        [str1]: false
      })
    }
    this.setData({
      [str]: true
    })


    for (var x in this.data.obj.yiji) {
      for (var y in this.data.obj.yiji[x].xiaji) {
        var str11 = "obj.yiji[" + x + "].xiaji[" + y + "].isselect"
        this.setData({
          [str11]: false
        })
      }
    }

    for (var x in this.data.obj.yiji) {
      if (this.data.obj.yiji[x].isselect) {
        for (var aa in this.data.obj.yiji[x].xiaji) {
          if (this.data.obj.yiji[x].xiaji[aa].canuse == true) {
            var str12 = "obj.yiji[" + x + "].xiaji[" + aa + "].isselect"
            this.setData({
              [str12]: true
            })
            var str111 = "obj.morenselect"
            this.setData({
              [str111]: this.data.obj.yiji[x].xiaji[aa].other
            })
            break
          }
        }
      }
    }


  },
  selectyiji1: function(e) {
    var index = e.currentTarget.dataset.index
    var str = "obj.yiji[" + index + "].isselect"
    for (var x in this.data.obj.yiji) {
      var str1 = "obj.yiji[" + x + "].isselect"
      this.setData({
        [str1]: false
      })
    }
    this.setData({
      [str]: true
    })

    for (var y in this.data.obj.yiji) {
      if (this.data.obj.yiji[y].isselect == true) {
        var str1111 = "obj.morenselect"
        this.setData({
          [str1111]: this.data.obj.yiji[y].other
        })
        return
      }
    }

  },
  selecterji: function(e) {
    var index = e.currentTarget.dataset.index

    console.log(index)
    for (var x in this.data.obj.yiji) {
      for (var y in this.data.obj.yiji[x].xiaji) {
        var str11 = "obj.yiji[" + x + "].xiaji[" + y + "].isselect"
        this.setData({
          [str11]: false
        })
      }
    }
    for (var x in this.data.obj.yiji) {
      if (this.data.obj.yiji[x].isselect) {
        var str12 = "obj.yiji[" + x + "].xiaji[" + index + "].isselect"
        this.setData({
          [str12]: true
        })
        var str111 = "obj.morenselect"
        this.setData({
          [str111]: this.data.obj.yiji[x].xiaji[index].other
        })
      }
    }
  },

  addcart: function(index, SKUID = "", OrderNumber = 1) {
    var info = this.data.nr.ProList[index]
    if (SKUID == "") {
      ajax('/api/ShopCart/AddCart?requestContent=' + JSON.stringify({
        token: wx.getStorageSync('Access_token'),
        ShopID: this.data.ID,
        ProuductPublishID: info.ID,
        ProductID: info.ProductID,
        OrderNumber: OrderNumber,
        IMoney: info.PrevsufferingPrice,
        OriPrice: info.OriPrice,
      }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "post",
      }, res => {
        // console.log(res)
        if (res.Status == 1) {
          this.getnr()
          this.getcart()
          // this.showsxselect()

        } else if (res.Status == 0) {
          this.getnr()
          wx.showToast({
            title: "添加失败",
            icon: 'none',
            duration: 2000
          })
          this.setData({
            quedingcanclick: true
          })
        } else if (res.Status == 2) {
          this.getnr()
          wx.showToast({
            title: "库存不足",
            icon: 'none',
            duration: 2000
          })
          this.setData({
            quedingcanclick:true
          })
        }

        // this.getcart()
      })
    } else {
      ajax('/api/ShopCart/AddCart?requestContent=' + JSON.stringify({
        token: wx.getStorageSync('Access_token'),
        ShopID: this.data.ID,
        ProuductPublishID: info.ID,
        ProductID: info.ProductID,
        SKUID: SKUID,
        OrderNumber: OrderNumber,
        IMoney: this.data.obj.morenselect.PrevsufferingPrice,
        OriPrice: info.OriPrice,
      }), {
        header: {
          'Accept': 'application/x-www-form-urlencoded', // 默认值
        },
        method: "post",
      }, res => {
        console.log(res)
        console.log("1111111111111111")

        if (res.Status == 1) {

          this.getcart()
          this.showsxselect()

        } else if (res.Status == 0) {
          wx.showToast({
            title: "添加失败",
            icon: 'none',
            duration: 2000
          })
          this.setData({
            quedingcanclick: true
          })
        } else if (res.Status == 2) {
          wx.showToast({
            title: "库存不足",
            icon: 'none',
            duration: 2000
          })
          this.setData({
            quedingcanclick: true
          })
        }

      })


    }
  },

  addcartbefor: function() {
    if (!this.data.quedingcanclick) {
      console.log("donggan")
      return
    }

    this.setData({
      quedingcanclick: false
    })

    this.addcart(this.data.obj.index, this.data.obj.morenselect.SKUID, this.data.obj.selfnum)
  },

  addobjselfnum: function() {
    var str = "obj.selfnum"
    this.setData({
      [str]: this.data.obj.selfnum + 1
    })
  },

  minusobjselfnum: function() {
    if (this.data.obj.selfnum != 1) {
      var str = "obj.selfnum"
      this.setData({
        [str]: this.data.obj.selfnum - 1
      })
    } else {
      return
    }

  },



  // #########################################################
  // CARLIST
  updatacarnum: function(index, VType) {
    ajax('/api/ShopCart/UpdateNums?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,

      SKUID: this.data.carlist[index].SKUID,
      ProuductPublishID: this.data.carlist[index].ProuductPublishID,
      OrderNumber: VType == 1 ? this.data.carlist[index].OrderNumber + 1 : this.data.carlist[index].OrderNumber - 1,
      ID: this.data.carlist[index].ID,
      VType: VType
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      if (res.Message == "库存不足") {
        wx.showToast({
          title: res.Message,
          icon: 'none',
          duration: 1000
        })
      }
      this.getcart()
      this.getnr()
    })
  },

  //car add
  caradd: function(e) {
    var index = e.currentTarget.dataset.index
    this.updatacarnum(index, 1)
  },
  carminus: function(e) {
    var index = e.currentTarget.dataset.index
    this.updatacarnum(index, 2)
  },
  // ###########################

  getcart: function() {
    ajax('/api/ShopCart/GetShopCart?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "get",
    }, res => {
      // console.log(res)

      this.setData({
        carlist: res.Models
      })
      //检测是否为全选
      for (var x in this.data.carlist) {
        if (this.data.carlist[x].IsChecked == false) {
          this.setData({
            selectall: false
          })
          break
        }
        this.setData({
          selectall: true
        })
      }
      this.jisuanallmoney()
    })
  },
  selectall: function(index = 1) {
    // console.log(index)
    this.quanxuan(!this.data.selectall)
    this.setData({
      selectall: !this.data.selectall
    })
  },

  jisuanallmoney: function() {
    var allmoney = 0
    var yixuan = 0
    var allcar = 0
    for (var x in this.data.carlist) {
      if (this.data.carlist[x].IsChecked) {
        allmoney += this.data.carlist[x].IMoney * this.data.carlist[x].OrderNumber
        // console.log(allmoney)
        yixuan += this.data.carlist[x].OrderNumber
      }
      allcar += this.data.carlist[x].OrderNumber
    }
    console.log(allmoney)
    this.setData({
      allmoney: allmoney.toFixed(2),
      yixuan: yixuan,
      allcar: allcar
    })
  },

  //quanxuan
  quanxuan: function(status) {
    for (var x in this.data.carlist) {
      if (this.data.carlist[x].IsChecked != status) {
        ajax('/api/ShopCart/UpdateChecked?requestContent=' + JSON.stringify({
          token: wx.getStorageSync('Access_token'),
          IsChecked: status,
          CartIDStr: this.data.carlist[x].ID
        }), {
          header: {
            'Accept': 'application/x-www-form-urlencoded', // 默认值
          },
          method: "post",
        }, res => {
          console.log(res)
          this.getcart()
        })
      }
    }
  },

  //修改选中状态

  updatedichecked: function(index) {
    ajax('/api/ShopCart/UpdateChecked?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      IsChecked: !this.data.carlist[index].IsChecked,
      CartIDStr: this.data.carlist[index].ID
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      this.getcart()
    })
  },



  clickdanxuan: function(e) {
    var index = e.currentTarget.dataset.index
    this.updatedichecked(index)
  },


  addselfnum: function(e) {

    if (!this.data.canadddandugoods) {
      console.log("donggan")
      return
    }

    this.setData({
      canadddandugoods: false
    })

    var index = e.currentTarget.dataset.index;
    // if (this.data.nr.ProList[index].selfnum==0){

    // }else{

    // }
    var ProNums = this.data.nr.ProList[index].ProNums + 1
    console.log(ProNums)
    var str = "nr.ProList[" + index + "].ProNums"
    this.setData({
      [str]: ProNums
    })
    this.clickadd(index)
  },


  minusselfnum: function(e) {

    if (!this.data.canminusdandugoods) {
      console.log("donggan")
      return
    }
    this.setData({
      canminusdandugoods: false
    })

    var index = e.currentTarget.dataset.index;
    if (this.data.nr.ProList[index].ProNums == 0) {
      return
    } else {
      var ProNums = this.data.nr.ProList[index].ProNums - 1
      console.log(ProNums)
      var str = "nr.ProList[" + index + "].ProNums"
      this.setData({
        [str]: ProNums
      })
    }
    this.updatacarnum1(index, 2)
  },
  // NR
  updatacarnum1: function(index, VType) {
    ajax('/api/ShopCart/UpdateNums?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,

      SKUID: 0,
      ProuductPublishID: this.data.nr.ProList[index].ID,
      OrderNumber: VType == 1 ? this.data.nr.ProList[index].ProNums : this.data.nr.ProList[index].ProNums,
      ID: this.data.nr.ProList[index].CartID,
      VType: VType
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      if (res.Message == "库存不足") {
        wx.showToast({
          title: res.Message,
          icon: 'none',
          duration: 1000
        })
      } else if (res.Message == "上传失败") {
        wx.showToast({
          title: res.Message,
          icon: 'none',
          duration: 1000
        })
      } else if (res.Message == "上传成功!") {
        this.getnr()
        this.getcart()
      }


    })
  },


  jiajianguanzhu: function() {
    ajax('/api/MyCollection/AttentionShop?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      ShopID: this.data.ID,
      VType: this.data.shopmsg.IsAttention ? 2 : 1
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)
      this.getshopinfo()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  tojiesuan: function() {
    if (this.data.canclick == false) {
      return
    }

    this.setData({
      canclick: false
    })

    // var query":[{"DealerID":39,"Orders":[{"PGID":372,"SKUID":733,"OrderNumber":1}]}],"
    var query = []
    var CartIDStr = ""
    var CartIDStrlist = []

    var DealerID = this.data.ID
    var objhu = {}
    var Orders = []
    objhu.DealerID = DealerID

    for (var x in this.data.carlist) {
      if (this.data.carlist[x].IsChecked) {
        var obj = {}
        obj.PGID = this.data.carlist[x].ProuductPublishID
        obj.SKUID = this.data.carlist[x].SKUID
        obj.OrderNumber = this.data.carlist[x].OrderNumber
        Orders.push(obj)
        CartIDStrlist.push(this.data.carlist[x].ID)
      }
    }
    objhu.Orders = Orders
    query.push(objhu)
    CartIDStr = CartIDStrlist.join(",")

    ajax('/api/ShopCart/UpdateState?requestContent=' + JSON.stringify({
      token: wx.getStorageSync('Access_token'),
      CartIDStr: CartIDStr,
      query: query
    }), {
      header: {
        'Accept': 'application/x-www-form-urlencoded', // 默认值
      },
      method: "post",
    }, res => {
      console.log(res)


      if (res.Message == "上传成功!") {
        wx.navigateTo({
          url: '/pages/sureorder/sureorder?CartIDStr=' + CartIDStr,
        })

      } else {
        this.setData({
          canclick: true
        })
        wx.showToast({
          title: res.Message,
          icon: 'none',
          duration: 2000
        })
      }
      // console.log("11111111111111111111111111111")

    })
  },
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getshopinfo()
    this.getclass()

    this.getshophuodong()
    this.getcart()

    this.setData({
      canclick: true
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})